﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Pozr.PozrServer;
using System.ServiceModel;

namespace Pozr
{
    public class ServiceWrapper
    {
        public void SendRawMeasurement(Measurement[] m)
        {
            try
            {
                PozrService s = new PozrService();
                s.Timeout = 5000;
                s.BeginSendRawMeasurement(m, new AsyncCallback(SendRawMeasurementCallback), s);
            }
            catch (Exception e)
            {
                Middleware.WriteLogToFile(e.Message);
            }
        }

        public void SendRawMeasurementCallback(IAsyncResult result)
        {
            try
            {
                PozrService s = (PozrService)result.AsyncState;
                Middleware.WriteLogToFile(s.EndSendRawMeasurement(result).ToString());
            }
            catch (System.Web.Services.Protocols.SoapException e)
            {
                switch (e.Message)
                {
                    case "QUERY_ERROR": Middleware.WriteLogToFile("Query error."); break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }

    }
}
